Support for PHP 8.5 pipe operator#9113
Conversation
Issue apache#9034 - include Php 8.5 version option - syntax support for pipe opperator - hint for basic non-callable pipe operator right handle : integer, float, bool, infix expression
|
I wonder if there is still time to include this in NB 29. |
@haidubogdan NB 29 is pretty much done unfortunately. There are no more RCs planned unless someone finds something release critical and we have to do another one. RC3 would become the release after vote. |
There was a problem hiding this comment.
Overall, the PR looks good to me, thanks a lot for it! 👍
If we can, please let's wait a bit for @junichi11 as he is the main guy working on the PHP support in NetBeans, thank you.
| "PhpVersion.PHP_82=PHP 8.2", | ||
| "PhpVersion.PHP_83=PHP 8.3", | ||
| "PhpVersion.PHP_84=PHP 8.4", | ||
| "PhpVersion.PHP_85=PHP 8.5", |
There was a problem hiding this comment.
An API class is changed -> we need to increase the version of this API module.
There was a problem hiding this comment.
(And this new version muist be used by other modules.)
| */ | ||
| PHP_84(Bundle.PhpVersion_PHP_84()), | ||
| /** | ||
| * PHP 8.4. |
There was a problem hiding this comment.
| * PHP 8.4. | |
| * PHP 8.5. |
| newIndent = Utilities.getRowIndent(doc, startExpression) + continuationSize; | ||
| break; | ||
| } | ||
| } else if (ts.token().id() == PHPTokenId.PHP_OPERATOR && TokenUtilities.textEquals("|>", ts.token().text())) { // NOI18N |
There was a problem hiding this comment.
Just curious - don't we use constants for these PHP operators?
| scan(node.getIfFalse()); | ||
| } | ||
|
|
||
|
|
| super(start, end); | ||
|
|
||
| if (right == null || left == null) { | ||
| throw new IllegalArgumentException(); |
There was a problem hiding this comment.
Please, add an exact error indicating what is wrong.
| case ASTPHP5Symbols.T_YIELD : text = "yield"; break; //NOI18N | ||
| case ASTPHP5Symbols.T_YIELD_FROM : text = "yield from"; break; //NOI18N | ||
| case ASTPHP5Symbols.T_READONLY : text = "readonly"; break; //NOI18N PHP 8.1 | ||
| //skiping T_PIPE = "|>" PHP 8.5 as it doesn't bring much to the expected tokens error message |
There was a problem hiding this comment.
I don't understand exactly why we are skipping the pipe here. Can you explain/provide an example?
There was a problem hiding this comment.
This change affects all the parser error messages + it's on a global version level, so the pipe operator will be suggested for Php 8.4 parser errors.
A lot of unit tests which shouldn't be impacted by the add of pipe operator will need to be recreated because it will mention pipe operator as a token suggestion.
| @Override | ||
| public String getDisplayName() { | ||
| return Bundle.PHP83VersionError_displayName(); | ||
| return Bundle.PHP84VersionError_displayName(); |
| @NbBundle.Messages("PHP85VersionError.description=Detected language features not compatible with PHP version indicated in project settings") | ||
| @Override | ||
| public String getDescription() { | ||
| return Bundle.PHP83VersionError_description(); |
There was a problem hiding this comment.
| return Bundle.PHP83VersionError_description(); | |
| return Bundle.PHP85VersionError_description(); |
| return createSymbol(ASTPHP5Symbols.T_SR_EQUAL); | ||
| } | ||
|
|
||
|
|
Part of issue #9034
Pipe Operator
The IDE doesn't support this operator today.
So it requires updates on the lexer and parser level.
For the pipe operator I've used a similar approach to the infix expression and based on this rfc : https://wiki.php.net/rfc/function-composition I've created a new AstNode CompositionExpression (Maybe it should be FunctionCompostionExpression ?).
Trying to identify what is a variable or what is not a callable seemed to be very hard as you can assign a callable to a variable. Also, as it's a chain type expression there are no clear syntax delimiters to be included, so it can't be implemented as a stand alone AST rule.
For the error syntax I've used a hint verification approach of identifying what type of expression is the right handle of a Composition Expression. The basic types of numeric tokens or boolean values can be marked directly as errors.
In some future implementation we can add checks on callable types, as they require to take only one parameter (first-class-callables) .
https://wiki.php.net/rfc/pipe-operator-v3#callable_styles
Todo | work in progress (while review is in progress :) )
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)